<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test JavaScript</title>
</head>
<body>
    <h1>Hello, World!</h1>
    <script>
        function parseSalesData(text) {
		  const lines = text.trim().split('\n');
		  let results = [];
		  let currentDate = '';

		  for (const line of lines) {
			const trimmedLine = line.trim();
			if(!trimmedLine){
				continue;
			}
			// 匹配日期行：如 "8月27日"
			const dateMatch = trimmedLine.match(/(\d+)月(\d+)日/);
			if (dateMatch) {
			  currentDate = `${dateMatch[1]}-${dateMatch[2]}`;
			  continue;
			}

			// 匹配销售记录：如 "安踏大店销售额12000元"
			const match = trimmedLine.match(/^(.+?)销售额(\d+)元$/);
			if (match) {
			  const shopName = match[1];        // 完整店铺名，如 "安踏大店"
			  const saleAmount = parseInt(match[2], 10); // 销售额数字

			  results.push({
				saleDate: currentDate,
				shopName: shopName,
				saleAmount: saleAmount
			  });
			}
			// 如果行不匹配，可选择忽略或报错
		  }

		  return results;
		}
		const text = "8月27日\n李宁大店销售额15000元\n安踏奥特莱斯店销售额8000元\n\n8月28日\n安踏一店销售额12000元"
		var result = parseSalesData(text);
		console.log(result);
    </script>
</body>
</html>
